package com.hh.vietnameseproject.ui.read

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.widget.LinearLayoutCompat
import com.hh.vietnameseproject.R
import com.hh.vietnameseproject.databinding.ActivityWebBinding
import com.just.agentweb.AgentWeb
import com.just.agentweb.DefaultWebClient

class WebActivity : AppCompatActivity() {
    lateinit var binding:ActivityWebBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityWebBinding.inflate(layoutInflater)
        setContentView(binding.root)
        val url = intent.getStringExtra("url")
        val name = intent.getStringExtra("nameTitle")
        binding.webTitle.text = name
        val mAgentWeb = AgentWeb.with(this)
            .setAgentWebParent(binding.myWebviewContainer, -1,
                LinearLayoutCompat.LayoutParams(-1, -1))
            .useDefaultIndicator()
            .setWebViewClient(com.just.agentweb.WebViewClient())
            .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)
            .createAgentWeb()
            .go(url)
        binding.webBack.setOnClickListener {
            onBackPressed()
        }

    }
    companion object{
        fun actionStartWebActivity(context: Context?,url:String,nameTitle:String){
            val intent = Intent(context,WebActivity::class.java)
            intent.putExtra("url",url)
            intent.putExtra("nameTitle",nameTitle)
            context?.startActivity(intent)
        }

    }
}